<?php	require_once(dirname(__FILE__).'/inc/config.inc.php');IsModelPriv('admanage');

/*
**************************
(C)2010-2015 phpMyWind.com
update: 2014-5-30 10:37:57
person: Feng
**************************
*/


//初始化参数
$tbname = '#@__admanage';
$gourl  = 'admanage.php';
$action = isset($action) ? $action : '';


//引入操作类
require_once(ADMIN_INC.'/action.class.php');


//添加广告信息
if($action == 'add')
{
	if ($_POST['lan'] == 'zh')
	{
		$classid = '1';
	}
	else
	{
		$classid = '2';
	}

	$r = $dosql->GetOne("SELECT `parentid` FROM `#@__adtype` WHERE `id`=$classid");
	$parentid  = $r['parentid'];
	$parentstr = $doaction->GetParentStr($parentid);

	$posttime = GetMkTime($posttime);

	if($_FILES['picurl']['error'] == 0)
	{
		//判断是否是通过HTTP POST上传的
		if(!is_uploaded_file($_FILES['picurl']['tmp_name']))
		{
			return('非法上传');
		}

		//开始移动文件到相应的文件夹
		$upload_path = "../uploads/image/".date('Ymd'); //上传文件的存放路径
		if (!file_exists($upload_path)) //检查文件是否存在
		{
			mkdir($upload_path);
		}

		//移动图片文件
		$picurl = $upload_path.'/'.time().$_FILES['picurl']['name'];
		move_uploaded_file($_FILES['picurl']['tmp_name'],$picurl);
		$picurl = substr($picurl,3);

		$sql = "INSERT INTO `$tbname` (siteid, classid, title, parentid, parentstr, admode, picurl, adtext, linkurl, posttime, orderid, checkinfo) VALUES ('$cfg_siteid', '$classid', '$title', '$parentid', '$parentstr', '$admode', '$picurl', '$adtext', '$linkurl', '$posttime', '$orderid', '$checkinfo')";
		if($dosql->ExecNoneQuery($sql))
		{
			header("location:$gourl");
			exit();
		}
	}
	else
	{
		echo"<script>alert('上传失败,请重试');history.go(-1);</script>";
	}
}


//修改广告信息
else if($action == 'update')
{
	$posttime = GetMkTime($posttime);

	//判断是否上传了图片
	if($_FILES['picurl']['error'] == 0)
	{
		//判断是否是通过HTTP POST上传的
		if(!is_uploaded_file($_FILES['picurl']['tmp_name']))
		{
			return('非法上传');
		}

		//开始移动文件到相应的文件夹
		$upload_path = "../uploads/image/".date('Ymd'); //上传文件的存放路径
		if (!file_exists($upload_path)) //检查文件是否存在
		{
			mkdir($upload_path);
		}

		//移动图片文件
		$picurl = $upload_path.'/'.time().$_FILES['picurl']['name'];
		move_uploaded_file($_FILES['picurl']['tmp_name'],$picurl);
		$picurl = substr($picurl,3);
	}
	elseif ($_FILES['picurl']['error'] == 4)
	{
		$picurl = $_POST['picurl_bak'];
	}
	else
	{
		echo"<script>alert('上传失败,请重试');history.go(-1);</script>";
	}

	$sql = "UPDATE `$tbname` SET siteid='$cfg_siteid', title='$title', admode='$admode', picurl='$picurl', adtext='$adtext', linkurl='$linkurl', posttime='$posttime', orderid='$orderid', checkinfo='$checkinfo' WHERE id=$id";
	if($dosql->ExecNoneQuery($sql))
	{
		header("location:$gourl");
		exit();
	}
}


//无条件返回
else
{
    header("location:$gourl");
	exit();
}
?>
